import sys
import time
from PyQt5.QtCore import *


class BulletTouch(QThread):
    sin = pyqtSignal(list, list)

    def getList(self, BulletList, EnemySetList):
        self.BulletList = BulletList
        self.EnemySetList = EnemySetList

    def run(self):
        for Bullet in self.BulletList:  # 遍历每个子弹
            if Bullet.isVisible():  # 若可视
                for EnemySet in self.EnemySetList:  # 遍历每个敌人集合列表
                    for Enemy in EnemySet.EnemyList:  # 在当前敌人集合中遍历每个敌人
                        if Enemy.isVisible():  # 若敌人可视(即敌人还活着)
                            if Bullet.collidesWithItem(Enemy):  # 若发送碰撞
                                Enemy.setBlood(Bullet.damage)
                                if Enemy.current_blood <= 0:
                                    Enemy.setVisible(False)  # 这个敌人设置为不可视
                                    # Enemy.smoke.setVisible(True)
                                    Enemy.CallSmoke()
                                    #Bullet.CallSmoke()
                                    Enemy.isshowblood = 0
                                    Enemy.current_blood = Enemy.blood
                                    Enemy.current_blood_front_x = Enemy.blood_front_x
                                else:
                                    Bullet.setVisible(False)  # 设置为不可视

                                Bullet.EnemySpark.setVisible(True)
                                Bullet.EnemySpark.setPos(Bullet.mapToScene(0,0))
                                Bullet.EnemySpark.update()
        self.sin.emit(self.BulletList, self.EnemySetList)  # 将两个列表传回
